package com.example.demo.controller;

import com.example.demo.service.LogService;
import com.example.demo.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RequestMapping("/trans2")
@RestController
@Slf4j
public class TransController2 {


    @Autowired
    private UserService userService;


    @Autowired
    private LogService logService;
//    @Transactional
    @RequestMapping("/r1")
    public boolean r1(String name,String password){
        Integer result = userService.registry(name,password);
        log.info("用户表影响行数: "+ result);
        Integer result2= logService.insert(name,password);
//        try{
//            int a =1/0;
//        }catch (Exception e){
//            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
//        }


        return true;
    }

}
